﻿package mortal.game.view.copy.guildDefenseCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.activeTime.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.guildDefenseCopy.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildDefenseCopyModule extends BaseWindow
    {
        private var _copyList:GTileList;
        private var _tipsBtnTxt:GTextFiled;
        private var _currentLevel:GTextFiled;
        private var _enterBtn:GLoadingButton;
        private var _currentCanEnterLevel:int;
        private var _selectIndex:int;

        public function GuildDefenseCopyModule(param1:ILayer = null)
        {
            super(param1);
            setSize(750, 546);
            title = Language.getString(35267);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = ActiveTimeUtil.getTodaySClientActiveTimeTxt(EActiveType._EActiveTypeGuildDefense);
            var _loc_2:* = GlobalStyle.textFormatHuang2;
            _loc_2.size = 13;
            this.pushUIToDisposeVec(UIFactory.bg(7, 35, 740, 507, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getStringByParam(35268, _loc_1), 12, 495, 300, 50, this, _loc_2, true));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildDefenceCopyTxt_1, 213, 47, this));
            _loc_2.size = 16;
            this._currentLevel = UIFactory.gTextField("", 368, 50, 200, 30, this, _loc_2);
            this._copyList = UIFactory.tileList(13, 86, 750, 542, this);
            this._copyList.columnWidth = 183;
            this._copyList.rowHeight = 404;
            this._copyList.horizontalGap = 0;
            this._copyList.setStyle("cellRenderer", GuildDefenseCopyRender);
            this._copyList.selectable = false;
            _loc_2 = GlobalStyle.textFormatLv;
            _loc_2.underline = true;
            this._tipsBtnTxt = UIFactory.gTextField(Language.getString(35269), 670, 503, 100, 20, this, _loc_2);
            this._tipsBtnTxt.toolTipData = Language.getStringByParam(35270, _loc_1);
            this._enterBtn = UIFactory.gLoadingButton(ResFileConst.EnterVipCopyBtn, 300, 495, 157, 36, this);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.enterCopy);
            this.updateCurrentIndex();
            this.updateCopyList();
            this.updateBtnState();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            EffectManager.glowFilterUnReg(this._enterBtn);
            this._copyList.dispose(param1);
            this._copyList = null;
            this._tipsBtnTxt.dispose(param1);
            this._tipsBtnTxt = null;
            this._currentLevel.dispose(param1);
            this._currentLevel = null;
            this._enterBtn.dispose(param1);
            this._enterBtn = null;
            return;
        }// end function

        private function updateCurrentIndex() : void
        {
            var _loc_3:TGuildDefenseCopy = null;
            var _loc_1:* = GuildDefenseConfig.instance.guildDefenseArr;
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.baseInfo.level;
            for each (_loc_3 in _loc_1)
            {
                
                if (_loc_2 >= _loc_3.level && _loc_3.level > this._currentCanEnterLevel)
                {
                    this._currentCanEnterLevel = _loc_3.level;
                    var _loc_6:String = this;
                    var _loc_7:* = this._selectIndex + 1;
                    _loc_6._selectIndex = _loc_7;
                }
            }
            return;
        }// end function

        public function updateCopyList() : void
        {
            this._copyList.dataProvider = this.getCopyDataProvider();
            return;
        }// end function

        public function updateBtnState() : void
        {
            var _loc_1:int = 0;
            this._copyList.selectedIndex = this._selectIndex - 1;
            if (Cache.instance.copy.guildDefence.isOpenCopy)
            {
                EffectManager.glowFilterReg(this._enterBtn);
            }
            else
            {
                EffectManager.glowFilterUnReg(this._enterBtn);
            }
            this.handleCellRendererChange();
            return;
        }// end function

        private function getCopyDataProvider() : DataProvider
        {
            var _loc_2:Object = null;
            var _loc_5:TGuildDefenseCopy = null;
            var _loc_6:int = 0;
            var _loc_1:* = new DataProvider();
            var _loc_3:* = Cache.instance.guild.selfGuildInfo.baseInfo.level;
            var _loc_4:* = GuildDefenseConfig.instance.guildDefenseArr;
            while (_loc_6 < _loc_4.length)
            {
                
                _loc_5 = _loc_4[_loc_6];
                _loc_2 = {index:_loc_6, info:_loc_5, level:this._currentCanEnterLevel};
                _loc_1.addItem(_loc_2);
                _loc_6++;
            }
            return _loc_1;
        }// end function

        private function enterCopy(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDefenseCopyEnter, Cache.instance.guild.selfGuildInfo.baseInfo.level));
            return;
        }// end function

        private function getLevelNameByIndex(param1:int) : String
        {
            var _loc_2:String = "";
            switch(param1)
            {
                case 1:
                {
                    _loc_2 = Language.getString(35271);
                    break;
                }
                case 2:
                {
                    _loc_2 = Language.getString(35272);
                    break;
                }
                case 3:
                {
                    _loc_2 = Language.getString(35273);
                    break;
                }
                case 4:
                {
                    _loc_2 = Language.getString(35274);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function handleCellRendererChange(event:Event = null) : void
        {
            this._currentLevel.htmlText = Language.getStringByParam(35275, this.getLevelNameByIndex(this._selectIndex));
            return;
        }// end function

    }
}
